package com.topscore.uke.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.TextView;

import com.topscore.uke.utils.ToolBarUtil;


/**
 * Created by Li Guoxi on 2016/5/30.
 */
public class ToolBarCompatActivity extends BaseCompatActivity {
    protected ToolBarUtil toolBarUtil;
    protected Toolbar toolbar;
    protected TextView mTitle_tv;
//    protected Context mContext;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        this.mContext = this;
    }

    @Override
    public void setContentView(int layoutResID) {
        toolBarUtil = new ToolBarUtil(this, layoutResID);
        toolbar = toolBarUtil.getToolbar();
        toolbar.setTitle("");
        mTitle_tv = toolBarUtil.getTitle_tv();
        setContentView(toolBarUtil.getContentView());
        setSupportActionBar(toolbar);
        onCreateCustomToolBar(toolbar);
    }

    protected void onCreateCustomToolBar(Toolbar toolbar) {
        toolbar.setContentInsetsRelative(0, 0);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            onBackPressed();
        }
        return super.onOptionsItemSelected(item);
    }

    protected Toolbar getToolbar(){
        return toolbar;
    }

    protected void setCentralTitle(@StringRes int stringId) {
        mTitle_tv.setText(stringId);
    }

    protected void setCentralTitle(String title) {
        mTitle_tv.setText(title);
    }

    protected void setCentralTitleColor(int color) {
        mTitle_tv.setTextColor(color);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

}
